<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">

        <title>Cocos Creator | CPMJ</title>

        <!--http://www.html5rocks.com/en/mobile/mobifying/-->
        <meta name="viewport"
              content="width=device-width,user-scalable=no,initial-scale=1, minimum-scale=1,maximum-scale=1"/>

        <!--https://developer.apple.com/library/safari/documentation/AppleApplications/Reference/SafariHTMLRef/Articles/MetaTags.html-->
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
        <meta name="format-detection" content="telephone=no">

        <!-- force webkit on 360 -->
        <meta name="renderer" content="webkit"/>
        <meta name="force-rendering" content="webkit"/>
        <!-- force edge on IE -->
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
        <meta name="msapplication-tap-highlight" content="no">

        <!-- force full screen on some browser -->
        <meta name="full-screen" content="yes"/>
        <meta name="x5-fullscreen" content="true"/>
        <meta name="360-fullscreen" content="true"/>

        <!-- force screen orientation on some browser -->
        <meta name="screen-orientation" content="landscape"/>
        <meta name="x5-orientation" content="landscape">

        <!--fix fireball/issues/3568 -->
        <!--<meta name="browsermode" content="application">-->
        <meta name="x5-page-mode" content="app">

        <!--<link rel="apple-touch-icon" href=".png" />-->
        <!--<link rel="apple-touch-icon-precomposed" href=".png" />-->

        <link rel="stylesheet" type="text/css" href="style-mobile.css"/>
        <script src="https://fa-ge.github.io/NativeShare/NativeShare.js" charset="utf-8"></script>
        <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
        <script src="http://wx.34537.com/Skin/Theme/Js/jquery_2.1.3.js" type="text/javascript" charset="utf-8"></script>


    </head>
    <body>
        <canvas id="GameCanvas" oncontextmenu="event.preventDefault()" tabindex="0"></canvas>
        <div id="splash">
            <div class="progress-bar stripes">
                <span style="width: 0%"></span>
            </div>
        </div>
        <script src="src/settings.js" charset="utf-8"></script>
        <script src="main.js" charset="utf-8"></script>

        <script charset="utf-8" id="protocols" type="text/javascript">
            var protocols = document.createElement("script");
            protocols.onload = function () {
                anysdk.agentManager.init();
                anysdk.agentManager.loadAllPlugins(function (code, msg) {
                });
            };
            protocols.src = "http://statics.h5.anysdk.com/protocols/protocols.js";
            document.body.appendChild(protocols);
        </script>
        <script>
            // 获取浏览器参数
            function getQueryString(name)
            {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null)
                    return  unescape(r[2]);
                return null;
            }
            // 获取浏览器推荐人变量u
            $(function () {
                var uid = getQueryString("u");
                if (uid) {
                    window.localStorage.setItem('referral_uid', uid);
                }
                // 如果未登录则跳到注册页面
                if(!window.localStorage.getItem('account')){
                    location.href='index.html';
                }
            })
        </script>
        <script>
            // 判断浏览器
            var browser = {
                versions: function () {
                    var u = navigator.userAgent, app = navigator.appVersion;
                    return {//移动终端浏览器版本信息
                        trident: u.indexOf('Trident') > -1, //IE内核
                        presto: u.indexOf('Presto') > -1, //opera内核
                        webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
                        gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
                        mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
                        ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
                        android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或uc浏览器
                        iPhone: u.indexOf('iPhone') > -1, //是否为iPhone或者QQHD浏览器
                        iPad: u.indexOf('iPad') > -1, //是否iPad
                        iPod: u.indexOf('iPod') > -1, //是否iPod
                        webApp: u.indexOf('Safari') == -1 //是否web应该程序，没有头部与底部
                    };
                }(),
                language: (navigator.browserLanguage || navigator.language).toLowerCase()
            }

            function checkIsIOS() {
                return (browser.versions.iPhone || browser.versions.iPad || browser.versions.iPod);
            }
            function checkIsAndroid() {
                return browser.versions.android;
            }
            function checkIsPC() {
                return !browser.versions.mobile;
            }
            function checkIsWeibo() {
                //在新浪微博客户端打开
                var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
                return (browser.versions.mobile && ua.match(/WeiBo/i) == "weibo");
            }
            function checkIsWechat() {
                //在微信中打开
                var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
                return (browser.versions.mobile && ua.match(/MicroMessenger/i) == "micromessenger");
            }
            function checkIsQzone() {
                //在QQ空间打开
                var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
                return (browser.versions.mobile && ua.match(/QQ/i) == "qq");
            }
        </script>
        <script type="text/javascript">
            // 先创建一个实例
            var nativeShare = new NativeShare();
            // 测试微信分享
            wxShare('标题', '描述', '', 'http://wx.34537.com/Skin/Theme/images/agent/adtext.png');
            // 微信分享调用方法
            function wxShare(title, desc, linkUrl, imageUrl) {
                if (!linkUrl) {
                    linkUrl = location.href.split('#')[0];
                }
                console.log(linkUrl);
                $.ajax({
                    type: "post",
                    async: false,
                    url: "http://wx.34537.com/publicservices/wxservice.aspx",
                    dataType: "jsonp",
                    jsonp: "cb", //传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                    jsonpCallback: "wxShareCallback", //自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名，也可以写"?"，jQuery会自动为你处理数据
                    data: {action: 'jsapiconf', shareurl: linkUrl},
                    success: function (json) {
                        wxShareCallback(json, title, desc, linkUrl, imageUrl);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        console.log(textStatus);
                        console.log(errorThrown);
                    }
                });
            }
            // jsonp回调方法
            function wxShareCallback(conf, title, desc, linkUrl, imageUrl) {
                console.log(conf);
                // 如果你需要在微信浏览器中分享，那么你需要设置额外的微信配置
// 特别提示一下微信分享有一个坑，不要分享安全域名以外的链接(具体见jssdk文档)，否则会导致你配置的文案无效
                nativeShare.setConfig({
                    wechatConfig: {
                        appId: conf.appid,
                        timestamp: conf.timestamp,
                        nonceStr: conf.noncestr,
                        signature: conf.signature,
                    }
                })
                // 设置分享文案
                nativeShare.setShareData({
                    icon: imageUrl,
                    link: linkUrl,
                    title: title,
                    desc: desc,
                    //from: '@fa-ge',
                })

// 唤起浏览器原生分享组件(如果在微信中不会唤起，此时call方法只会设置文案。类似setShareData)
                try {
                    if (checkIsWechat()) {
                        // 如果是分享到微信则需要 
                        nativeShare.call('wechatFriend')
                    } else {
                        nativeShare.call()
                    }
                    // 类似的命令下面有介绍
                } catch (err) {
                    // 如果不支持，你可以在这里做降级处理
                }
            }
        </script>
    </body>
</html>
